home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / MATH2 / POWERI.PAS < prev    next >
Pascal/Delphi Source File  |  1985-05-17  |  2KB  |  56 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*                     PowerI -- raise real to integer power                *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION PowerI( x: REAL; i: INTEGER ) : REAL;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*      Function:  PowerI                                                   *)
  10. (*                                                                          *)
  11. (*      Purpose:   Performs exponentiation of real to integer power.        *)
  12. (*                                                                          *)
  13. (*      Calling Sequence:                                                   *)
  14. (*                                                                          *)
  15. (*         Powval := Power( x : REAL; i: INTEGER ) : REAL;                  *)
  16. (*                                                                          *)
  17. (*            x      --- base                                               *)
  18. (*            i      --- power to raise base to                             *)
  19. (*                                                                          *)
  20. (*      Calls:     None                                                     *)
  21. (*                                                                          *)
  22. (*--------------------------------------------------------------------------*)
  23.  
  24. VAR
  25.    Temp: REAL;
  26.    AbsI: INTEGER;
  27.  
  28. BEGIN (* PowerI *)
  29.  
  30.    IF i < 0 THEN
  31.       BEGIN
  32.          i := -i;
  33.          IF x <> 0.0 THEN x := 1.0 / x;
  34.       END;
  35.  
  36.    Temp := 1.0;
  37.  
  38.    WHILE( i > 0 ) DO
  39.       BEGIN
  40.  
  41.          WHILE ( NOT ODD( i ) ) DO
  42.             BEGIN
  43.                i := i DIV 2;
  44.                x := x * x;
  45.             END;
  46.  
  47.          i    := i - 1;
  48.          Temp := Temp * x;
  49.  
  50.       END;
  51.  
  52.    PowerI := Temp;
  53.  
  54. END   (* PowerI *);
  55.  
  56.